//
//  SelectAddressView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/30.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "SelectAddressView.h"

@interface SelectAddressView()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UILabel *linkerLB;

@property (nonatomic,strong) UILabel *addressLB;

@property (nonatomic,strong) UIImageView *toDetailImgV;

@property (nonatomic,strong) UIImageView *bottomLineV;

@end

@implementation SelectAddressView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = MainBackColor;
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(AddressModel *)model{
    _model = model;
    if ([_model.province isEmpty] == NO && _model.province.length>0) {
        self.addressLB.text = [NSString stringWithFormat:@"%@ %@ %@ %@",_model.province,_model.city,_model.region,_model.address];
        self.linkerLB.text = [NSString stringWithFormat:@"%@ %@",_model.linker,_model.linkphone];
    }
}
#pragma mark - UI
-(void)initUI{
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.linkerLB];
    [self.bgView addSubview:self.addressLB];
    [self.bgView addSubview:self.toDetailImgV];
    [self.bgView addSubview:self.bottomLineV];
    
    self.bgView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAddressClick:)];
    tap.delegate = self;
    [self.bgView addGestureRecognizer:tap];
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 102)];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
- (UILabel *)linkerLB{
    if (!_linkerLB) {
        _linkerLB = [[UILabel alloc] initWithFrame:CGRectMake(25, 15, ScreenWidth - 70, 20)];
        _linkerLB.backgroundColor = UIColor.whiteColor;
        _linkerLB.text = @"请选择收货人";
        _linkerLB.font = FontSet(15);
        _linkerLB.textColor = MainBlackTextColor;
    }
    return _linkerLB;
}
- (UILabel *)addressLB{
    if (!_addressLB) {
        _addressLB = [[UILabel alloc] initWithFrame:CGRectMake(25, self.linkerLB.bottom + 5, ScreenWidth - 70, 40)];
        _addressLB.numberOfLines = 2;
        _addressLB.backgroundColor = UIColor.whiteColor;
        _addressLB.text = @"请选择收货地址";
        _addressLB.font = FontSet(15);
        _addressLB.textColor = MainBlackTextColor;
    }
    return _addressLB;
}

- (UIImageView *)toDetailImgV{
    if (!_toDetailImgV) {
        _toDetailImgV = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 36, 45, 6, 10)];
        _toDetailImgV.image = LoadImage(@"个人中心_查看全部");
    }
    return _toDetailImgV;
}
- (UIImageView *)bottomLineV{
    if (!_bottomLineV) {
        _bottomLineV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 98, ScreenWidth-30, 4)];
        _bottomLineV.image = LoadImage(@"地址_底部线条");
    }
    return _bottomLineV;
}

#pragma mark - SEL
-(void)selectAddressClick:(UIGestureRecognizer *)ges{
    if (self.selectAddressBlock) {
        self.selectAddressBlock();
    }
}

@end
